<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*" %>
<%@ page import="com.augurit.wf.common.constant.WfConstant" %>
<%@page import="com.augurit.common.system.web.auth.form.LoginUserForm"%>
<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;

 %>
 <%LoginUserForm form=(LoginUserForm)request.getSession().getAttribute("SES_LOGIN_USER"); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>打印</title>
    	<%@ include file="/wf/public/meta_wf.jsp"%>
	<!--设置缓存-->
	<meta http-equiv="cache-control" content="no-cache,must-revalidate"/>
	<meta http-equiv="pragram" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>
 	<script src="${ctx}/common/apabiPrint/js/gaizhang.js" type="text/javascript"></script>
	<script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
	<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
	<script type='text/javascript' src="${ctx}/dwr/interface/FileUploadCntl.js"></script>
	<script  type="text/javascript" src="${ctx}/resources/js/jquery/jquery.js"></script>
	<script src="${ctx}/gzcgwsp/resources/js/prototype.js" type="text/javascript"></script>
	<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
	<script src="${ctx}/gzcgwsp/resources/js/YwGrid.js" type="text/javascript"></script>
	<script src="${ctx}/resources/js/aos/tool.js" type="text/javascript"></script>
	<script src="${ctx}/resources/components/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	<script src="${ctx}/resources/js/jquery/jquery.js" type="text/javascript"></script>
	<script language="javascript" src="${ctx}/resources/components/ntko/OfficeContorlFunctions.js"></script>
	<script language="JavaScript" src="${ctx}/gzcgwsp/wfex/client/common/js/wf-attachment-public.js"></script>
	
	<link rel="stylesheet" type="text/css" href="${ctx}/gzcgwsp/resources/css/common-ui.css" />
	
	<script type="text/javascript">
	function setview(){

	}
		var contextpath="<%=basePath%>";
		var fileSavePath=getPathBySystem(); 
		var basepath="${ctx}";
		//根据操作系统用不同的路径
		function getPathBySystem(){
		     var path="";
		     var ua = navigator.userAgent.toLowerCase();
		     if(ua.indexOf("linux")>=0){
		        path="/usr/local/temp";
		     }else{
		        path="C:\\TEMP\\";
		     }
		    return path;
		}
		

	     //保存
       function gzDocument(){
       	 		var filepath=document.getElementById("templateFilePath").value;
				 var chinesename = document.getElementById("sqdw").value+
         				  document.getElementById("acceptNo").value+"许可证.doc";
		           var filepath=contextpath+document.getElementById("templateFilePath").value;
		  		   var filename = filepath.substring(filepath.lastIndexOf("/")+1);
		  		   TransUpload(filename,chinesename,filepath);
						
       }
	function TransUpload(result,chinesename,filepath){
			var newpath=MakeWord(result,chinesename,filepath);// 打开word ，把它保存在D盘，相当于下载
			var DocName, CebName, LogName, IniName;
			var DocNameLen;
			var DocNameWONLen;
			var cebtail;
		//	DocName = NewDocForm.OriginalFile.value;
		 	DocName =newpath;
			DocNameLen = DocName.length;
			DocNameWONLen = DocName.lastIndexOf(".") - 1;
			if (DocNameWONLen == -1){
				DocNameWONLen = DocNameLen;
			}else{
				cebtail = DocName.substring(DocNameWONLen+2, DocNameLen);
			}
			if (cebtail.toLowerCase() == "ceb"){
				CebName = DocName;
			}else{
				CebName = DocName.substring(0, DocNameWONLen+1) + ".ceb";
			}
			
			LogName = DocName.substring(0, DocNameWONLen+1) + ".log";
			IniName = DocName.substring(0, DocNameWONLen+1) + ".ini";
			if (DocName != CebName){
				if (!(transMaker(DocName, CebName, LogName, IniName))){// 格式转换
					alert("格式转换失败，请重试！");
					return false;
				}		
			}
			else{
				alert("当前格式为ceb格式！");
			}
			var f=newpath.substring(0,newpath.lastIndexOf("."))+".ceb";
		
			Stamp_onclick(f);//盖章
			 var ieflag=checkIeVersion();
			 if(ieflag){
				 	//document.getElementById("t1").value=f;
					//callSet(fileTitle);//上传
					//Ext.getBody().mask("附件上传中");
			 		fileupload(f,'${id}','${templateCode}',chinesename);
			 		window.close();
			  }else{
			 	//Ext.getBody().mask("附件上传中");
			 	fileupload(f,'${id}','${templateCode}',chinesename);
			 	window.close();
			  }
			return true;

		}
			//弹出上传文件的窗口
	function fileWin(chinesename,uploadName){
		var ajid='${id}';
		var templateCode='${templateCode}';
		var username='<%=form.getUser().getUserName() %>';
		var dotIndex =uploadName.lastIndexOf(".");
		if (dotIndex < 0) dotIndex = uploadName.length;
		var attacheName = chinesename;
		var attacheType = uploadName.substring(dotIndex + 1);
		new Ext.Window({
		    id        : 'fileWin',
		    title     : '选择证书',
		    width     : 450,
		    height    : 150,
		    modal     : true,
		    plain     : true,
		    resizeable: false,
	        html: '<br>' +
	       '<form action="${ctx}/yw-com-print!uploadAttach.action"  enctype="multipart/form-data" id="fileform" name="fileform" method="post" target="upload-target">' +
	       '<input type="hidden" name="templateCode" value="'+templateCode +'"/>'+
	        '<input type="hidden" name="ajid" value="' +ajid+'"/>'+
	         '<input type="hidden" name="attacheName" value="' +attacheName+'"/>'+
	         '<input type="hidden" name="filetype" value="' +attacheType+'"/>'+
	         '<input type="hidden" name="username" value="' +username+'"/>'+
	        '<table width="100%" border="0">' +
	        '    <tr>' +
	        '        <td align="right" height="25">选择证件：</td>' +
	        '        <td colspan="3"><input type="file" id="attacheBrow" name="attach"  size="35" class="tpl_list_ui"/></td>' +
	        '    </tr>' +
	        '    <tr>' +
	        '        <td colspan="4" align="center">&nbsp;</td>' +
	        '    </tr>' +
	        '    <tr>' +
	        '        <td colspan="4" align="center">' +
	        '            <input type="button" value="上  传" onclick="uploadFile();" class="tpl_list_ui"/>' +
	        '            &nbsp;&nbsp;&nbsp;&nbsp;' +
	        '            <input type="button" value="取  消" onclick="Ext.getCmp(\'fileWin\').hide();" class="tpl_list_ui"/>' +
	        '        </td>' +
	        '    </tr>' +
	        '</table>' +
	        '<iframe name="upload-target" style="display:none;"></iframe>' +
	        '</form>' +
	    ''
	  }).show();
	}

	function uploadFile(){
	  document.getElementById("fileform").submit();
	}
		
		//格式转换
		function transMaker(DocName, CebName, LogName, IniName){
			var DTracker;
			DTracker = new ActiveXObject("MakerCom.MakerExt.1");
			var nRet;
			var Error;
			//alert("正转换文件，请稍候......");		
			nRet = DTracker.BeginMaker("");
			if (nRet != 0){
				alert(DTracker.GetErrorMessage(nRet));		
				delete DTracker;
				return false;
			}		
		    //alert("开始文档格式转换......请稍后!");		
			nRet = DTracker.SingleFileConvert(DocName, CebName, "标准模板", LogName, IniName);	
			if (nRet != 0){
				alert("MakerOcx transfer error!");
				nRet = DTracker.EndMaker();		
				delete DTracker;
				return false;
			}
			nRet = DTracker.EndMaker();
			if (nRet != 0){
				alert("MakerOcx End error!");		
				delete DTracker;
				return false;
			}	
			alert("格式转换完成！");	
			delete DTracker;
			return true;
		}
		//文件保存到本地
		 function MakeWord(filename,chinesename,filepath){
		    var WordApp=new ActiveXObject("Word.Application");
		     WordApp.Application.Visible=false; 
            WordApp.NormalTemplate.Saved = true;
	        var newpath=fileSavePath+chinesename;
	        var url=filepath;
	        var Doc=WordApp.Documents.Add(url,false);
	        Doc.saveAs(newpath);
	        Doc.Close();
	        WordApp.Application.Quit();
	        return newpath;
 		}
		 		
		  //判断ie的版本，如果是6.0或者7.0返回true;
		function checkIeVersion(){
			var browser=navigator.appName 
			var b_version=navigator.appVersion 
			var version=b_version.split(";"); 
			var trim_Version=version[1].replace(/[ ]/g,""); 
			if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){ 
				return true;
			} else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){ 
				return false;
			} else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE8.0"){ 
				return false;
			} else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0") { 
				return false;
			} else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0") { 
				return false;
			}else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0") { 
				return false;
			}
			return true;
		}
 		
	</script>
<script language="vbs">
	Function Stamp_onclick(strCEBFileName)    	
		Dim strErrMessage, lRet, objStampClientTool,g_AffixRegisterURL,g_SendPrintURL,UnitName
		g_AffixRegisterURL="http://172.16.253.169/StampServer/interfaces/background/AffixRegister.aspx"
		g_SendPrintURL="http://172.16.253.169/StampServer/extend/interfaces/SendPrint.aspx"
		UnitName=""
		lRet = ""
		strErrMessage = ""
		strCEBFileName = trim(strCEBFileName)
		if  0 = len(trim(strCEBFileName)) then
			Call Alert("请选择CEB文件！", vbExclamation, "请选择CEB文件！")
			Exit Function
		else
			if UCase(Right(Trim(strCEBFileName), 3)) <> "CEB" then
				Call Alert("只能选择CEB格式的文件！", vbExclamation, "只能选择CEB格式的文件！")
				CEBFileName.value = ""
				Exit Function
			end if                  	 	  
		end if
		set objStampClientTool  = CreateObject("StampClientTool.StampTool")
		' 本地可视化盖章	
		lRet = objStampClientTool.LocalSealStamp(strCEBFileName, UnitName, g_AffixRegisterURL, g_SendPrintURL)	
		if lRet <> 0 then
		strErrMessage = objStampClientTool.GetErrorMessage()
        alert "盖章失败原因:" & strErrMessage
		end if
	Set objStampClientTool = Nothing	
	End Function
</script>
<script LANGUAGE="JavaScript">
	//简化写法
	function $(id){
	    return document.getElementById(id);
	}
	//崋值方法(就是将文本框的值赋值file对象)
	function set1(){
	    //将text1中的值复制到剪贴板中
	    window.clipboardData.setData('text',$('t1').value); 
	    //创建Shell(需要添加到信任站点或解除未签名的ActiveX控件的禁用
	    var   WshShell=new   ActiveXObject("WScript.Shell"); 
	    //拿到焦点
	    $('f1').focus();
	    //Ctrl + A 操作
	    WshShell.sendKeys("^a");
	    //Ctrl + V 操作(sendKeys对于中文赋值操作显得无力,所以只能模拟键盘操作)
	    WshShell.sendKeys("^v");
	    
	}
	
	//给当前网页中四个file对象赋值的方法
	function set(chinesename){
	    //此处不要用循环,有几个就需要写几个setXX方法
	    setTimeout("set1()",3000);
	    setTimeout("upload('"+chinesename+"')",2000);
	}
	//检查是否赋值成功
	function check(){
	    //检查每个file对象是否为空 
	    if($('f1').value.length > 0){
	        //检查原对象的值的赋值对象的值是否相同
	        if($('f1').value == $('t1').value){
	            return true;
	        }else{
	            return false;
	        }
	    }else{
	        return false;
	    }
	}
	//赋值和file对象的检查
	function setValues(chinesename){
	    if(!check()){
	        set(chinesename);
	    }
	}
	//直接调用的赋值方法
	function callSet(chinesename){
	    //一定要用setInterval,而不能用循环(循环太快,会造成所有的值赋在一个file对象上)
	    //setInterval('setValues()',1000);
	    setValues(chinesename);    
	}
	
   function upload(chinesename){
	var attache = dwr.util.getValue('f1');
	var uploadName=dwr.util.getValue('f1').value;
	if (uploadName == '') { 
	     uploadName=$('t1').value;
	    //Ext.Msg.alert("提示!","上传失败!");return;
	}
	var ajid='${id}';
	var username='<%=form.getUser().getUserName() %>';
	var dotIndex =uploadName.lastIndexOf(".");
	if (dotIndex < 0) dotIndex = uploadName.length;
	var attacheName = chinesename;
	var attacheType = uploadName.substring(dotIndex + 1);
	var obj;	
	 obj ={
	  ajid:ajid,
	  username:username,
	  filename:attacheName,
	  filetype:attacheType
	  };	
		
	var params=Ext.encode(obj);
	FileUploadCntl.uploadDzgz(params, attache, function (result){
	       Ext.Msg.alert("提示!","上传成功!");
	       //window.location.reload(); 
	       //viewStore.load();
	});
	}
	
	
	//弹出上传文件的窗口
	function fileWin(chinesename,uploadName){
		var ajid='${id}';
		var templateCode='${templateCode}';
		var username='<%=form.getUser().getUserName() %>';
		var dotIndex =uploadName.lastIndexOf(".");
		if (dotIndex < 0) dotIndex = uploadName.length;
		var attacheName = chinesename;
		var attacheType = uploadName.substring(dotIndex + 1);
		new Ext.Window({
		    id        : 'fileWin',
		    title     : '选择证书',
		    width     : 450,
		    height    : 150,
		    modal     : true,
		    plain     : true,
		    resizeable: false,
	        html: '<br>' +
	       '<form action="${ctx}/yw-com-print!uploadAttach.action"  enctype="multipart/form-data" id="fileform" name="fileform" method="post" target="upload-target">' +
	       '<input type="hidden" name="templateCode" value="'+templateCode +'"/>'+
	        '<input type="hidden" name="ajid" value="' +ajid+'"/>'+
	         '<input type="hidden" name="attacheName" value="' +attacheName+'"/>'+
	         '<input type="hidden" name="filetype" value="' +attacheType+'"/>'+
	         '<input type="hidden" name="username" value="' +username+'"/>'+
	        '<table width="100%" border="0">' +
	        '    <tr>' +
	        '        <td align="right" height="25">选择证件：</td>' +
	        '        <td colspan="3"><input type="file" id="attacheBrow" name="attach"  size="35" class="tpl_list_ui"/></td>' +
	        '    </tr>' +
	        '    <tr>' +
	        '        <td colspan="4" align="center">&nbsp;</td>' +
	        '    </tr>' +
	        '    <tr>' +
	        '        <td colspan="4" align="center">' +
	        '            <input type="button" value="上  传" onclick="uploadFile();" class="tpl_list_ui"/>' +
	        '            &nbsp;&nbsp;&nbsp;&nbsp;' +
	        '            <input type="button" value="取  消" onclick="Ext.getCmp(\'fileWin\').hide();" class="tpl_list_ui"/>' +
	        '        </td>' +
	        '    </tr>' +
	        '</table>' +
	        '<iframe name="upload-target" style="display:none;"></iframe>' +
	        '</form>' +
	    ''
	  }).show();
	}
	
	function uploadFile(){
	  document.getElementById("fileform").submit();
	}
	
	function resultValue(result){
	 var faile = Ext.decode(result);
		if(faile.msg==false){
			Ext.Msg.alert("提示!","上传失败!");
		}else{
		    Ext.Msg.alert("提示!","上传成功!");
		    //删除c:temp下的文件
			deleteFile();
		    Ext.getCmp('fileWin').close();
		    window.location.reload(); 
		}
	}
	
	function  viewGzFile(path,filename){
		filename=filename.substring(0,filename.lastIndexOf("."));
		filename+=".ceb";
		filename=encodeURI(encodeURI(filename));
		var url="yw-com-print!checkFile.action?url="+path;
		//检查文件是否存在
		 Ext.Ajax.request({
		     url:url,
		     method:'POST',
		     timeout:900000,
		     method:'POST',
		     success:function(response){
		         var msg=response.responseText;
		         if(msg=="true"){
					window.location.href = "${ctx}/common/downloadfile.jsp?filepath="+path+"&filename="+filename;  
				}else{
					alert('文件不存在！');
				}
			},
		    failure: function() {
		        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
		        myMask.hide();
		     } 
	   });
	}
</script>
	
	
</head>
<body onload='setview();intializePage("${ctx}/bi/wf-template-print-ref-ex!readPrintTemplateFile.action?ywId=${id}&templateId=${param.templateId}&templateCode=${param.templateCode}&fileCode=${param.fileCode}");' topmargin="0" leftmargin="0">
	
	<!-- 广州城管委行政审批修改 开始 -->
	<form action="${ctx}/printDoc/yw-print-doc!save.action?ywId=${id}&templateCode=${param.templateCode}&fileCode=${param.fileCode}&templateId=${param.templateId}" enctype="multipart/form-data" method="post">
    <!---------------- 工具栏 开始 ----------------->
    <input type="hidden"  id="activName" name="activName" value="${activName}"/>
     <input type="hidden"  id="ywId" name="ywId" value="${id}"/>
     <input type="hidden" name="acceptNo" id="acceptNo" value="${acceptNo}"/>
	 <input type="hidden" name="templateFilePath" id="templateFilePath" value="${templateFilePath}">
	<input type="hidden" name="sqdw" id="sqdw" value="${sqdw}"/>
    <table class="tb_custom">
        <tr>
            <td class="td_header_l" id="saveFile" >&nbsp;
                 <input type="button" value=" 盖章 " onclick="gzDocument()"/>&nbsp;
           	</td>
            <td>
            	 <input type="button" value=" 退 出 " onclick="window.close()"/>
               	 <input type="button" value=" 控件下载 " onclick="ocxDownLoad()"/>
                </td>
        </tr>
    </table>
    </form>
    <!-- 广州城管委行政审批修改 结束 -->
    
	<script type="text/javascript" src="${ctx}/resources/components/ntko/genOfficeControl.js"></script> 
	<script language="JScript" for=NTKO_OCX event="OnDocumentOpened(TANGER_OCX_str,TANGER_OCX_obj)">
		setFileOpenedOrClosed(true);
		printRecord();
		NTKO_OCX.SetReadOnly(true);
		     saveDocumentRemoveTrack();
	      var url="${ctx}/smart-form-csdlwj!getXkzFilePath.action?ywId=${id}&templateId=${param.templateId}&templateCode=${param.templateCode}&fileCode=${param.fileCode}";
 		  	 Ext.Ajax.request({
			     url:url,
			     method:'POST',
			     timeout:900000,
			     method:'POST',
			     success:function(response){
			         var msg=response.responseText;
			        document.getElementById("templateFilePath").value=msg;
				},
			    failure: function() {
			        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
			        myMask.hide();
			     } 
		   });
	  		  	
	  
		
	</script>
	
	<script type="text/javascript">
		function printRecord(){
		<%
			Map map = (Map)request.getAttribute(WfConstant.PRINT_BUFFER);				    	
			if(map != null){
				Iterator it = map.entrySet().iterator();
				while(it.hasNext()){
					Map.Entry entry = (Map.Entry)it.next();
					String value="";
					if(entry.getValue()!=null){
					    value = entry.getValue().toString();						
						if( value.indexOf("\n") >= 0){
							value = value.replace("\n", "\\n");
							value = value.replace("\r", "\\r");
						}
					}
											
		%>
					NTKO_OCX.SetbookmarkValue("<%=entry.getKey()%>", "<%= value%>");
		<%		
				}
			}
		%>
		}
		
		//ntko控件下载
       function ocxDownLoad(){
            location.href="${ctx}/resources/components/ntko.rar";
       }
	</script>
			
	<!-- 以下函数相应控件的两个事件:OnDocumentClosed,和OnDocumentOpened -->
	<script language="JScript" for=NTKO_OCX event="OnDocumentClosed()">
		setFileOpenedOrClosed(false);
	</script>		
	    
</body>
</html>
